
<?
include('wallet_db.html');

$main_info=translate('main_info');
$show_client=translate('show_client');
$cl_det=translate('cl_det');
$current_upgr=translate('current_upgr');
$change_upgr=translate('change_upgr');
$change_upgr_ok=translate('change_upgr_ok');
$upg_error=translate('upg_error');
if($_SERVER['REMOTE_ADDR']=='213.222.51.218'){
	$upg_error = $upg_error."debug";
}
$no_clients=translate('no_clients');

if($errorMsg) {
include ('errorMsg.html');
}
if($okMsg) {
include ('okMsg.html');
}
else {
}

$paz='ups';
$params[sid] = $sid;
$params[action] = "editClientsUpgrades";
$url = "$baseURL/$webDIR/?".encode_params($params);

if (isset($_POST[hid_var]) && $_POST[hid_var]=='345') {
	$client_id=$_POST[client_id];
	//------------------------------------------------------
        $sql['type']='SELECT';
        $sql['params']='a.username, a.firstname, a.lastname, a.server, b.db_user, b.db_host, b.db_pass, b.db_name';
        $sql['table']='clients as a, servers as b';
        $sql['where']="a.client_id='$client_id' and a.server=b.name";
        $sql['options']='';
        $sql['return']='struct';
        //------------------------------------------------------
        if (!$result=sql_exec($sql,$dbh81,'assoc')) {
                translate_error('upg_error');
                exit;
                //exit("$upg_error");
        }
	$serv_info=$result[0];
	$ph_dbuser=$serv_info[db_user];
	$ph_dbhost=$serv_info[db_host];
	$ph_dbpass=$serv_info[db_pass];
	$ph_dbname=$serv_info[db_name];
	$ph_dbh = pg_connect("dbname=".$ph_dbname." host=".$ph_dbhost." user=".$ph_dbuser." password=".$ph_dbpass."");


	//iprint_r($serv_info);
	if (!$ph_dbh) {
	//	print "resource: $ph_dbh\n<BR>";
                translate_error('upg_error');
                exit;
		//exit("$upg_error");
	}
	//------------------------------------------------------
        $sql['type']='SELECT';
        $sql['params']='upgrade';
        $sql['table']='plans';
        $sql['where']="user_id='$client_id'";
        $sql['options']='';
        $sql['return']='struct';
        //------------------------------------------------------
        if (!$result=sql_exec($sql,$ph_dbh,'assoc')) {
                translate_error('upg_error');
                exit;
                //exit("$upg_error");
        }
	$upgrade=$result[0][upgrade];
	if ($upgrade==1) {
		$ch='checked';
		$ch1='';
	} elseif ($upgrade==0) {
		$ch='';
		$ch1='checked';
	}
	echo "<div align=left><p>$cl_det <b>$serv_info[firstname] $serv_info[lastname] - $serv_info[username]</b></p>";
	echo "<table class='bTable' cellspacing=0>
	<form action='$url' method='POST'>
	<tr>
		<td align=right valign=top width=\"50%\">$current_upgr :</td>
		<td align=left valign=top width=\"50%\"><input type=radio name=upgrade value=0 $ch1> off</br>
			<input type=radio name=upgrade value=1 $ch> on</td>
	</tr>
	<tr>
		<td colspan=2 align=center><input type=submit name=submit value='$change_upgr'><input type=hidden name=hid_var value='678'><input type=hidden name=client_id value='$client_id'></td>
	</tr>
	</form></table>";
} elseif (isset($_POST[hid_var]) && $_POST[hid_var]=='678') {
	$client_id=$_POST[client_id];
	//------------------------------------------------------
        $sql['type']='SELECT';
        $sql['params']='a.username, a.firstname, a.lastname, a.server, b.db_user, b.db_host, b.db_pass, b.db_name';
        $sql['table']='clients as a, servers as b';
        $sql['where']="a.client_id='$client_id' and a.server=b.name";
        $sql['options']='';
        $sql['return']='struct';
        //------------------------------------------------------
        if (!$result=sql_exec($sql,$dbh81,'assoc')) {
                translate_error('upg_error');
                exit;
                //exit("$upg_error");
        }
	$serv_info=$result[0];
	$ph_dbuser=$serv_info[db_user];
	$ph_dbhost=$serv_info[db_host];
	$ph_dbpass=$serv_info[db_pass];
	$ph_dbname=$serv_info[db_name];
	$ph_dbh = @pg_connect("dbname=".$ph_dbname." host=".$ph_dbhost." user=".$ph_dbuser." password=".$ph_dbpass."");
	if (!$ph_dbh) {
                translate_error('upg_error');
                exit;

		//exit("$upg_error");
	}
	$par[upgrade]=$_POST[upgrade];
	//------------------------------------------------------
        $sql['type']='UPDATE';
        $sql['params']=$par;
        $sql['table']='plans';
        $sql['where']="user_id='$client_id'";
        $sql['options']='';
        $sql['return']='';
        //------------------------------------------------------
        if (!$result=sql_exec($sql,$ph_dbh,'assoc')) {
                translate_error('upg_error');
                exit;
              //exit("$upg_error");
        }
//	echo "$change_upgr_ok";
		$okMsg = translate('change_upgr_ok');
		include_once('okMsg.html');

} else {
	//------------------------------------------------------
	$sql['type']='SELECT';
	$sql['params']='client_id, username';
	$sql['table']='clients';
	$sql['where']="reseller_id='$id' AND blocked=0";
	$sql['options']='';
	$sql['return']='struct';
	//------------------------------------------------------
	if (!$result=sql_exec($sql,$dbh81,'assoc')) {
                #translate_error('no_clients');
                #exit;
		exit("<b>$no_clients</b>");
	}
	foreach ($result as $value) {
		$clients[$value[client_id]]=$value[username];
	}
	echo "<form action='$url' method='POST'>
	<div align=left><p>$main_info</p>
	<select name='client_id'>
	<option value=0>----------</option>\n";
	foreach ($clients as $key=>$val) {
		echo "<option value='$key'>$val</option>\n";
	}
	echo "</select>&nbsp;
	<input type=submit name=submit value='$show_client'><input type='hidden' name='hid_var' value='345'></form></div>";
}
?>
